package whu.o2o;

import java.util.ArrayList;

import whu.o2o.View.LoadDialog;
import whu.o2o.adapter.DiaryAdapter;
import whu.o2o.util.ConstantData;
import whu.o2o.util.ParseXml;
import whu.o2o.vo.CommentVO;
import whu.o2o.vo.DiaryVO;
import whu.o2o.vo.ImageVO;
import whu.o2o.vo.PersonVO;
import android.os.Bundle;
import android.widget.ListView;

import whu.o2o.R;
import whu.o2o.connection.CommonHttpConnect;
import whu.o2o.connection.Params;




/**
 * �����ռ�
 * 
 * @author aa
 * 
 */
public class GuideDiaryAcivity extends DiaryBaseActivity {
	private ListView mListView;
	private DiaryAdapter mAdapter;
	private ArrayList<DiaryVO> mDiaryList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_common_diary_list);
		initObject();
		initView();
		initListener();
		initData();
	}

	@Override
	protected void parseData(final String xml) {
		mApplication.getThreadPool().execute(new Runnable() {

			@Override
			public void run() {
				ParseXml.getInstance().parseDiaryXml(xml, mDiaryList);
				mHttpListHandler.sendEmptyMessage(ConstantData.Data.PARSE_XML_MSG_CODE);
			}
		});

	}

	@Override
	protected void setAdapter() {
		if (mAdapter == null) {
			mAdapter = new DiaryAdapter(this, mDiaryList, ConstantData.Data.DEFAULT_DIARY_TYPE);
			mListView.setAdapter(mAdapter);
		} else {
			mAdapter.notifyDataSetChanged();

			if (mFirstPage) {
				scrollTop(mListView);
			}
		}
	}

	private void initObject() {
		mDiaryList = new ArrayList<DiaryVO>();
	}

	private void initView() {
		setTitle("家纺百货");
		mListView = (ListView) findViewById(R.id.listView);
	}

	private void initListener() {
		backBtnClick();
		findViewById(R.id.write).setOnClickListener(this);
	}

	private void initData() {
		String[] times = { "1分钟前", "2分钟前", "3分钟前" };
		String[] contents = { "武汉大学购物优惠券限时发放！", "元旦购物优惠券疯狂奔袭，快来抢啊！", "出售生活用品若干，有意者联系，QQ：123456789" };
		int[] states = { 0, 0, 0 };

		String[] names = { "姬大哥", "赵大哥", "钟大哥" };
		int[] userIds = { 322, 128, 224 };
		int[] ages = { 32, 18, 24 };
		int[] sexs = { 0, 1, 0 };
		boolean[] validateds = { true, true, true };

		for (int i = 0; i < contents.length; i++) {
			DiaryVO diaryVO = new DiaryVO();

			PersonVO personVO = new PersonVO();
			personVO.setId(userIds[i]);
			personVO.setName(names[i]);
			personVO.setSex(sexs[i]);
			personVO.setAge(ages[i]);
			personVO.setValidated(validateds[i]);

			ArrayList<ImageVO> images = new ArrayList<ImageVO>();
			images.add(new ImageVO());

			ArrayList<CommentVO> comments = new ArrayList<CommentVO>();
			CommentVO commentVO1 = new CommentVO();
			commentVO1.setType(0);
			ArrayList<PersonVO> goodList = new ArrayList<PersonVO>();
			for (int j = 0; j < names.length; j++) {
				PersonVO personVOGood = new PersonVO();
				personVOGood.setName(names[j]);
				goodList.add(personVOGood);
			}
			commentVO1.setGoodList(goodList);

			CommentVO commentVO2 = new CommentVO();
			commentVO2.setType(1);
			PersonVO personVOComment = new PersonVO();
			personVOComment.setName(names[i]);
			commentVO2.setUser(personVOComment);
			commentVO2.setContent(contents[i]);
			comments.add(commentVO1);
			comments.add(commentVO2);

			diaryVO.setUser(personVO);
			diaryVO.setContent(contents[i]);
			diaryVO.setTime(times[i]);
			diaryVO.setSendState(states[i]);
			diaryVO.setImages(images);
			//diaryVO.setComments(comments);

			mDiaryList.add(diaryVO);
		}

		setAdapter();

		// requestData(BaseActivity.FIRST_PAGE);
	}

	private void requestData(int page) {

	}
}
